package com.base.social.signature.support;

import com.base.core.codec.Base64Utils;
import com.base.social.signature.SignatureTemplate;

import java.util.Map;

public class DingTalkSignature extends SignatureTemplate {

    /**
     * 生成钉钉请求的Signature
     *
     * 参数选项
     * secretKey 平台应用的授权密钥
     * timestamp 时间戳
     * @param params 签名参数
     * @return Signature
     */
    @Override
    public String generateSignature(Map<String, Object> params) {
        String secretKey = params.get("secretKey").toString();
        String timestamp = params.get("timestamp").toString();
        byte[] signData = sign(secretKey.getBytes(DEFAULT_ENCODING), timestamp.getBytes(DEFAULT_ENCODING), HMAC_SHA_256);
        return urlEncode(new String(Base64Utils.encode(signData, false)));
    }
}
